import time

from selenium.webdriver.common.by import By
from pom.base_page import BasePage


class SysMonitorPage(BasePage):
    def online_user(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[3]/li/ul/div[1]/a/li').click()

        time.sleep(2)
        browser_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[1]/div[3]//tr[1]/td[7]/div').text
        login_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[1]/div[3]//tr[1]/td[3]/div').text
        print(browser_name, login_name, "**********************")

        assert browser_name == "Chrome 10"
        assert login_name == "admin"

        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[2]/div/div/input').send_keys("admin")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[3]/div/button[1]').click()

        time.sleep(1.5)
        s_browser_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[1]/div[3]//tr[1]/td[7]/div').text
        s_login_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[1]/div[3]//tr[1]/td[3]/div').text
        print(s_browser_name, s_login_name, "**********************")

        assert s_browser_name == "Chrome 10"
        assert s_login_name == "admin"

    def scheduled_tasks(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[3]/li/ul/div[2]/a/li').click()

        time.sleep(3)
        task_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        task_group = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text
        print(task_name, task_group, "**********************")

        assert task_name == "系统默认（有参）"
        assert task_group == "默认"

    def data_monitoring(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[3]/li/ul/div[3]/a/li').click()

        time.sleep(2)

    def service_monitoring(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[3]/li/ul/div[4]/a/li').click()

        time.sleep(2)
        cpu = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div/div[1]/div/div[1]/div/span').text
        memory = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div/div[2]/div/div[1]/div/span').text
        print(cpu, memory, "**********************")

        assert cpu == "CPU"
        assert memory == "内存"

    def cache_monitoring(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[3]/li/ul/div[5]/a/li').click()

        time.sleep(2)
        redis_version = self.driver.find_element(By.XPATH,
                                                 '//div[2]/div/div[2]//div/div/div[1]/div/div[2]/div//tr[1]/td[2]/div').text
        port = self.driver.find_element(By.XPATH,
                                        '//div[2]/div/div[2]//div/div/div[1]/div/div[2]/div//tr[1]/td[6]/div').text
        print(redis_version, port, "**********************")

        assert redis_version == "7.0.4"
        assert port == "6379"

    def cache_list(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[3]/li/ul/div[6]/a/li').click()

        time.sleep(2)
        cache_name = self.driver.find_element(By.XPATH,
                                              '//div[2]/div/div[2]//div/div/div[1]/div/div[2]/div/div[3]//tr[1]/td['
                                              '2]/div').text
        remarks = self.driver.find_element(By.XPATH,
                                           '//div[2]/div/div[2]//div/div/div[1]/div/div[2]/div/div[3]//tr[1]/td[3]/div').text
        print(cache_name, remarks, "**********************")

        assert cache_name == "login_tokens"
        assert remarks == "用户信息"
